var DataTypes = require("sequelize").DataTypes;
var _buy_medicine = require("./buy_medicine");
var _diagnose = require("./diagnose");
var _doctor_medicine_lib = require("./doctor_medicine_lib");
var _dose = require("./dose");
var _drug_sort = require("./drug_sort");
var _foresee = require("./foresee");
var _medicine_enterprise = require("./medicine_enterprise");
var _medicine_lib = require("./medicine_lib");
var _month_medicine_lib = require("./month_medicine_lib");
var _patient = require("./patient");
var _prescription = require("./prescription");
var _prescription_sheet = require("./prescription_sheet");
var _sysinfo = require("./sysinfo");
var _user = require("./user");

function initModels(sequelize) {
  var buy_medicine = _buy_medicine(sequelize, DataTypes);
  var diagnose = _diagnose(sequelize, DataTypes);
  var doctor_medicine_lib = _doctor_medicine_lib(sequelize, DataTypes);
  var dose = _dose(sequelize, DataTypes);
  var drug_sort = _drug_sort(sequelize, DataTypes);
  var foresee = _foresee(sequelize, DataTypes);
  var medicine_enterprise = _medicine_enterprise(sequelize, DataTypes);
  var medicine_lib = _medicine_lib(sequelize, DataTypes);
  var month_medicine_lib = _month_medicine_lib(sequelize, DataTypes);
  var patient = _patient(sequelize, DataTypes);
  var prescription = _prescription(sequelize, DataTypes);
  var prescription_sheet = _prescription_sheet(sequelize, DataTypes);
  var sysinfo = _sysinfo(sequelize, DataTypes);
  var user = _user(sequelize, DataTypes);

  prescription.belongsTo(diagnose, { as: "diagnose_sort", foreignKey: "diagnose_sort_id"});
  diagnose.hasMany(prescription, { as: "prescriptions", foreignKey: "diagnose_sort_id"});
  prescription_sheet.belongsTo(doctor_medicine_lib, { as: "doctor_medicine_lib", foreignKey: "doctor_medicine_lib_id"});
  doctor_medicine_lib.hasMany(prescription_sheet, { as: "prescription_sheets", foreignKey: "doctor_medicine_lib_id"});
  medicine_lib.belongsTo(dose, { as: "dose_dose", foreignKey: "dose"});
  dose.hasMany(medicine_lib, { as: "medicine_libs", foreignKey: "dose"});
  prescription_sheet.belongsTo(dose, { as: "dose_dose", foreignKey: "dose"});
  dose.hasMany(prescription_sheet, { as: "prescription_sheets", foreignKey: "dose"});
  medicine_lib.belongsTo(drug_sort, { as: "sort", foreignKey: "sort_id"});
  drug_sort.hasMany(medicine_lib, { as: "medicine_libs", foreignKey: "sort_id"});
  medicine_lib.belongsTo(medicine_enterprise, { as: "manufacturer_medicine_enterprise", foreignKey: "manufacturer"});
  medicine_enterprise.hasMany(medicine_lib, { as: "medicine_libs", foreignKey: "manufacturer"});
  buy_medicine.belongsTo(medicine_lib, { as: "medicine_lib", foreignKey: "medicine_lib_id"});
  medicine_lib.hasMany(buy_medicine, { as: "buy_medicines", foreignKey: "medicine_lib_id"});
  doctor_medicine_lib.belongsTo(medicine_lib, { as: "medicine_lib", foreignKey: "medicine_lib_id"});
  medicine_lib.hasMany(doctor_medicine_lib, { as: "doctor_medicine_libs", foreignKey: "medicine_lib_id"});
  month_medicine_lib.belongsTo(medicine_lib, { as: "medicine_lib", foreignKey: "medicine_lib_id"});
  medicine_lib.hasMany(month_medicine_lib, { as: "month_medicine_libs", foreignKey: "medicine_lib_id"});
  prescription_sheet.belongsTo(medicine_lib, { as: "medicine_lib", foreignKey: "medicine_lib_id"});
  medicine_lib.hasMany(prescription_sheet, { as: "prescription_sheets", foreignKey: "medicine_lib_id"});
  buy_medicine.belongsTo(patient, { as: "patient", foreignKey: "patient_id"});
  patient.hasMany(buy_medicine, { as: "buy_medicines", foreignKey: "patient_id"});
  foresee.belongsTo(patient, { as: "patient", foreignKey: "patient_id"});
  patient.hasMany(foresee, { as: "foresees", foreignKey: "patient_id"});
  prescription.belongsTo(patient, { as: "patient_patient", foreignKey: "patient"});
  patient.hasMany(prescription, { as: "prescriptions", foreignKey: "patient"});
  prescription_sheet.belongsTo(prescription, { as: "prescription", foreignKey: "prescription_id"});
  prescription.hasMany(prescription_sheet, { as: "prescription_sheets", foreignKey: "prescription_id"});
  buy_medicine.belongsTo(user, { as: "nurse", foreignKey: "nurse_id"});
  user.hasMany(buy_medicine, { as: "buy_medicines", foreignKey: "nurse_id"});
  doctor_medicine_lib.belongsTo(user, { as: "conservator_user", foreignKey: "conservator"});
  user.hasMany(doctor_medicine_lib, { as: "doctor_medicine_libs", foreignKey: "conservator"});
  doctor_medicine_lib.belongsTo(user, { as: "doctor_user", foreignKey: "doctor"});
  user.hasMany(doctor_medicine_lib, { as: "doctor_doctor_medicine_libs", foreignKey: "doctor"});
  foresee.belongsTo(user, { as: "doctor", foreignKey: "doctor_id"});
  user.hasMany(foresee, { as: "foresees", foreignKey: "doctor_id"});
  medicine_lib.belongsTo(user, { as: "conservator_user", foreignKey: "conservator"});
  user.hasMany(medicine_lib, { as: "medicine_libs", foreignKey: "conservator"});
  prescription.belongsTo(user, { as: "doctor_user", foreignKey: "doctor"});
  user.hasMany(prescription, { as: "prescriptions", foreignKey: "doctor"});

  return {
    buy_medicine,
    diagnose,
    doctor_medicine_lib,
    dose,
    drug_sort,
    foresee,
    medicine_enterprise,
    medicine_lib,
    month_medicine_lib,
    patient,
    prescription,
    prescription_sheet,
    sysinfo,
    user,
  };
}
module.exports = initModels;
module.exports.initModels = initModels;
module.exports.default = initModels;
